import scrapy
from scrapy import Selector
from scrapy.http import HtmlResponse

from webspider.items import WebspiderItem

# 学习地址：https://scrapy-chs.readthedocs.io/zh-cn
class IqiyiSpider(scrapy.Spider):
    name = "iqiyi"
    allowed_domains = ["www.iqiyi.com"]
    start_urls = ["https://www.iqiyi.com"]


    def parse(self, response: HtmlResponse):
        print("我是谁")
        sel = Selector(response)
        items = sel.css("#result-list > div > ul > li")
        for item in items:
            iem = WebspiderItem()
            iem['title'] = item.css("h3 > a::attr(title)").extract_first()
            iem['author'] = item.css(".author .name::text").extract_first()
            iem['about'] = item.css(".intro::text").extract_first()
            yield iem
